import * as power from '@/api/recruitment'
export default {
  data() {
    return {
      // 薪资
      salaryMinList: [
        {
          label: '面议',
          value: 0
        },
        {
          label: '1K',
          value: 1000
        },
        {
          label: '2K',
          value: 2000
        },
        {
          label: '3K',
          value: 3000
        },
        {
          label: '4K',
          value: 4000
        },
        {
          label: '5K',
          value: 5000
        },
        {
          label: '6K',
          value: 6000
        },
        {
          label: '7K',
          value: 7000
        },
        {
          label: '8K',
          value: 8000
        },
        {
          label: '9K',
          value: 9000
        },
        {
          label: '10K',
          value: 10000
        },
        {
          label: '11K',
          value: 11000
        },
        {
          label: '12K',
          value: 12000
        },
        {
          label: '13K',
          value: 13000
        },
        {
          label: '14K',
          value: 14000
        },
        {
          label: '15K',
          value: 15000
        },
        {
          label: '16K',
          value: 16000
        },
        {
          label: '17K',
          value: 17000
        },
        {
          label: '18K',
          value: 18000
        },
        {
          label: '19K',
          value: 19000
        },
        {
          label: '20K',
          value: 20000
        }
      ],
      provinceList: [], // 省
      cityList: [], // 市
      areaList: [], // 区
      jobStatusList: [], // 求职状态
      arrTimeList: [], // 到岗时间
      WelfareList: [], // 获取福利
      educationList: [], // 学历
      levelList: [], // 层级
      teacherModeList: [], // 授课方式
      liveCityList: [] // 现居市

    }
  },
  methods: {
    // 根据市cityCode查询区
    getAreaList(pid) {
      power.getArea({ pid }).then((res) => {
        this.areaList = res.data
      })
    },
    // 获取求职状态
    getJobStatus() {
      power.getJobStatus().then((res) => {
        this.jobStatusList = res.data
      })
    },
    // 获取到岗时间
    get_Arrive_Time_List() {
      power.getArriveTime().then((res) => {
        this.arrTimeList = res.data
      })
    },
    // 获取福利
    get_Welfare_List() {
      power.getWelfare().then((res) => {
        this.WelfareList = res.data
      })
    },
    // 获取学历
    getEducationList() {
      power.getEducation().then((res) => {
        this.educationList = res.data
      })
    },
    // 查询层级
    get_Level_List() {
      power.getLevelList().then((res) => {
        this.levelList = res.data
      })
    },
    // 授课方式
    checkTeacherMode() {
      power.getTeacherMode().then((res) => {
        this.teacherModeList = res.data
      })
    },
    // 获取全部省份
    get_Province_List() {
      power.getProvince().then((res) => {
        this.provinceList = res.data
      })
    },
    // 根据provinceCode获取市
    getCityList(pid) {
      power.getCity({ pid }).then((res) => {
        this.cityList = res.data
      })
    },
    getLiveCityList(pid) {
      power.getCity({ pid }).then((res) => {
        this.liveCityList = res.data
      })
    },
    // 计算年龄/工作年限 (一年毫秒数(365 * 86400000 = 31536000000))
    computedAgeOrWorkTime(timeer, boolean = true) {
      const nowTime = new Date().getTime() + ''
      const subTime = nowTime.substring(0, nowTime.length - 3)
      if (boolean) {
        return Math.floor(((+subTime - timeer) / 31536000000) * 1000)
      } else {
        return ((+subTime - timeer) / 31536000000) * 1000
      }
    },
    // 获取兴趣教育列表
    getIntentionTotalPositionList() {
      power.getIntentionList().then((res) => {
        this.interestList = res.data.filter((item) => {
          return item.name !== '附近机构' && item.name !== '学科辅导'
        })
        this.options[1].children = this.interestList.map((item) => {
          const childrenObj = {
            label: item.name,
            value: JSON.stringify({
              id: item.id,
              name: item.name
            }),
            children: []
          }
          item.categories.forEach((key) => {
            const obj = {
              value: JSON.stringify({
                id: key.id,
                name: key.name
              }),
              label: key.name
            }
            childrenObj.children.push(obj)
          })
          return childrenObj
        })
      })
    },
    // 获取学科辅导列表
    getSubjectPositionList() {
      power.getSubjectList({ parentId: 104, flagEnable: 1 }).then((res) => {
        this.subjectList = res.data
        this.options[0].children = res.data.map((item) => {
          const childrenObj = {
            label: item.name,
            value: JSON.stringify({
              id: item.id,
              name: item.name
            })
          }
          return childrenObj
        })
      })
    },
    // 删除经历确认框
    confirmDialog(world, array, index) {
      this.$confirm(`此操作将永久删除该${world},是否继续?`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        array.splice(index, 1)
        this.$message({
          type: 'success',
          message: '删除成功!'
        })
      })
    },
    // 现居省
    select_Live_Provice(e) {
      this.profile.accountProfile.liveAddressCity = ''
      this.provinceList.forEach((item) => {
        if (e === item.provinceName) {
          this.getLiveCityList(item.provinceCode)
          this.provinceCode = item.provinceCode
        }
      })
    },
    // 现居市
    select_Live_City() {
      this.profile.accountProfile.liveAddressRegion = ''
      this.liveCityList.forEach((item) => {
        if (this.profile.accountProfile.liveAddressCity === item.cityName) {
          this.getAreaList(item.cityCode)
          this.cityCode = item.cityCode
        }
      })
    },
    // 现居区
    select_Live_Region() {
      this.areaCode = this.areaList.find((item) => item.areaCode === this.profile.accountProfile.liveAddressRegion)
      this.profile.accountProfile.liveAddressCode = `${this.provinceCode},${this.cityCode},${this.areaCode}`
    },
    // 授课方式
    chooseMode() {
      this.profile.jobIntention.teacherModeName = this.teacherModeList.find((item) => item.id === this.profile.jobIntention.teacherModeId).name
    },
    // 选取学历
    select_Education() {
      this.profile.accountProfile.educationName = this.educationList.find((item) => item.id === this.profile.accountProfile.educationId).name
    },
    // 是否公开简历
    is_Open_Resume() {
      this.profile.accountProfile.isPublic = this.isPublic === true ? '1' : '0'
    },
    // 选取层级
    chooseLevel() {
      this.profile.jobIntention.hierarchyName = this.levelList.find((item) => item.id === this.profile.jobIntention.hierarchyId).name
    },

    // 选取求职状态
    chooseJobStatus() {
      this.profile.jobIntention.jobWantedName = this.jobStatusList.find((item) => item.id === this.profile.jobIntention.jobWantedStatusId).name
    },
    // 选取到岗时间
    chooseArrTimeName() {
      this.profile.jobIntention.startTimeName = this.arrTimeList.find((item) => item.id === this.profile.jobIntention.startTimeId).name
    },
    // 选取福利
    chooseWelfarName() {
      this.welfarTypeName.forEach((item) => {
        this.WelfareList.forEach((item1) => {
          if (item === item1.name) {
            this.welfarIdName.push(item1.id)
          }
        })
      })
      this.welfarIdName = [...new Set(this.welfarIdName)]
      this.profile.jobIntention.welfareIds = this.welfarIdName.join(',')
      this.profile.jobIntention.welfareNames = this.welfarTypeName.join(',')
    },
    // 教育经历的学历选取
    chooseEducationExp() {
      this.EducationExperience.educationName = this.educationList.find((item) => item.id === this.EducationExperience.educationId).name
    },
    // 意向省市
    handleProvice(e) {
      this.handleResume === '添加老师' ? (this.profile.jobIntention.intentionCityCode = '') : false
      this.getCityList(e)
      this.profile.jobIntention.intentionProvinceName = this.provinceList.find((item) => item.provinceCode === e).provinceName
    },
    // 意向城市
    handleCity(e) {
      this.profile.jobIntention.intentionCityName = this.cityList.find((item) => item.cityCode === e).cityName
    }
  }
}
